package com.senthink.gl.business.domain.service;

import com.senthink.gl.business.common.exception.DataAccessException;
import com.senthink.gl.business.domain.repository.VerifyCodeRepository;
import com.senthink.gl.business.forgetpw.VerifyCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * 校验码数据服务
 * @author yuanpeng@senthink.com
 * @data 2018-02-28 10:57
 */

@Service
public class VerifyCodeDataService {

    @Autowired
    private VerifyCodeRepository repository;

    public VerifyCode save(VerifyCode verifyCode) {
        try {
            return repository.save(verifyCode);
        } catch (Exception e) {
            throw new DataAccessException(e);
        }
    }

    public Optional<VerifyCode> findTopByAccount(String account) {
        try {
            return repository.findTopByAccount(account);
        } catch (Exception e) {
            throw new DataAccessException(e);
        }
    }

    public void deleteByAccount(String account) {
        try {
            repository.deleteByAccount(account);
        } catch (Exception e) {
            throw new DataAccessException(e);
        }
    }
}
